import RTNSensors from "./NativeSensors";
// Cache the availability of sensors
const availableSensors = {};

export function start(type) {
  switch (type) {
    case 'accelerometer':
      RTNSensors.accelerometer();
      break;
    case 'gyroscope':
      RTNSensors.gyroscope();
      break;
    case 'magnetometer':
      RTNSensors.magnetometer();
      break;
    case 'barometer':
      RTNSensors.barometer();
      break;
    case 'orientation':
      RTNSensors.orientation();
      break;
    case 'gravity':
      RTNSensors.gravity();
      break;
    default:
  }
}

export function isAvailable(type) {
  if (availableSensors[type]) {
    return availableSensors[type];
  }
  const promise = RTNSensors.isAvailable(type);
  availableSensors[type] = promise;

  return promise;
}

export function stop(type) {
  RTNSensors.off(type);
}

export function setUpdateInterval(type, updateInterval) {
  RTNSensors.setUpdateInterval(type, updateInterval);
}

export function setLogLevelForType(type, level) {
  RTNSensors.setLogLevel(type, level);
}
